package com.sunday.msq.fragment;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.sunday.frame.ViewInject;
import com.sunday.frame.adapter.AdvertisementAdapter;
import com.sunday.msq.R;
import com.sunday.msq.activity.QuestionAddActivity;
import com.sunday.msq.widget.AutoScrollViewPager;

/**
 * 首页
 * @author SunshineHu
 *
 */
public class IndexFragment extends Fragment implements OnClickListener{

	@ViewInject(value=R.id.right_btn,onclick=true)
	private ImageView right;
	
	private OnClickListener bannerListener=new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			
		}
	};
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		loadView();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return inflater.inflate(R.layout.index_fragment, null);
	}
	
	private void loadView(){
		
		TextView title=(TextView) getActivity().findViewById(R.id.title);
		title.setText("美术圈");
		
		AutoScrollViewPager viewpager=(AutoScrollViewPager) getActivity().findViewById(R.id.viewpager);
		viewpager.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,  (int) (getActivity().getWindowManager().getDefaultDisplay().getWidth()/2.37)));
		
		List<String> lists=new ArrayList<String>();
		lists.add("drawable://"+R.drawable.index_banner);
		lists.add("drawable://"+R.drawable.index_banner);
		AdvertisementAdapter adapter=new AdvertisementAdapter(getActivity(), lists, bannerListener);
		viewpager.setAdapter(adapter);
		viewpager.setScrollFactgor(5);
		viewpager.setOffscreenPageLimit(4);
		viewpager.startAutoScroll(4000);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.right_btn:
			Intent in=new Intent(getActivity(), QuestionAddActivity.class);
			startActivity(in);
			break;
		}
	}
	

}
